using UnityEngine;
using System.Collections;

public class AsteroidScript : MonoBehaviour {
	public int explosionNumber = 1;
	public int explosionRadius = 10;
	public int hitPoints = 10;
	public GameObject explosion;
	public int points = 100;

	// Use this for initialization
	void Start () {
	}

	// Update is called once per frame
	void OnTriggerEnter2D(Collider2D other) {
		if ( other.tag == "PlayerLaser" ) {
			PlayerShipShots_Script lazer = other.gameObject.GetComponent<PlayerShipShots_Script>();
			lazer.Die();
			hitPoints -= 1;
		}
		else if ( other.tag == "DrillBaby" ) {
			PlayerDrillShots_Script drill = other.gameObject.GetComponent<PlayerDrillShots_Script>();
			drill.Drill(gameObject);
	    }
		if ( hitPoints <= 0 || other.tag == "Ship" )
		{
			if ( hitPoints <= 0 ){
				HighScore.score += points;
			}
			if(explosionNumber > 1)
			{
				for (int i = 0; i < explosionNumber; i++) {
					Vector3 pos = transform.position;
					pos.x += 0.1f * Random.Range(-explosionRadius,explosionRadius);
					pos.y += 0.1f * Random.Range(-explosionRadius,explosionRadius);
					Instantiate (explosion, pos, transform.rotation); //Instantiate explosion
				}
			}
			else
			{
				Instantiate (explosion, transform.position, transform.rotation); //Instantiate explosion
			}
			Destroy(gameObject);
		}
	}

	void Update() {
		if ( hitPoints <= 0 ){
			HighScore.score += points;
			Instantiate (explosion, transform.position, transform.rotation); //Instantiate explosion
			Destroy(gameObject);
		}
	}
}